#include "searcher.hpp"
#include <iostream>
#include "cpp-httplib/httplib.h"
std::string input = "date/raw_html/raw.txt";
const std::string root_path = "./wwwroot";
int main()
{
    us_searcher::Searcher *searcher = new us_searcher::Searcher();
    searcher->InitSearcher(input);
    httplib::Server server;
    server.set_base_dir(root_path);

    server.Get("/s", [&searcher](const httplib::Request &req, httplib::Response &res) {
        if(!req.has_param("word"))
        {
            res.set_content("请输入关键字","text/plain; chatset=utf-8");//纯文本 utf-8
            return;
        }
        std::string word=req.get_param_value("word");
        std::string json_string;
        searcher->Search(word,&json_string);
        res.set_content(json_string,"application/json");
    });
    server.Get("/",[](const httplib::Request &req, httplib::Response &res){

        std::string out;
        us_util::FileUtil::ReadFile("index.html",&out);
        res.set_content(out,"text/html");

    });
    server.listen("0.0.0.0",8081);

    return 0;
}